package com.origin.baselibrary.activity.style

import androidx.databinding.ViewDataBinding
import androidx.lifecycle.ViewModelProvider
import com.origin.baselibrary.viewmodel.BaseViewModel
import com.origin.utils.gson.GsonUtils
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.MainScope
import java.lang.reflect.ParameterizedType

/**
 * DataBinding 页面数据于xml数据交互
 * ViewModel 数据请求
 * LiveData 将ViewModel的数据返回给页面
 * MutableLiveData 将作为数据在三方中流传
 * 或者
 * ObservableField 将作为数据在三方中流传
 */
abstract class ViewModelActivity<VB : ViewDataBinding, VM : BaseViewModel>(open var viewModelActivityLayout: Int = 0, override var isSafeDis: Boolean = true, override var isOpenImmersive: Boolean = true) : ImmersiveActivity<VB>(viewModelActivityLayout, isSafeDis, isOpenImmersive), CoroutineScope by MainScope() {


    val viewModel: VM by lazy {
        ViewModelProvider(this).get(getTClass())
    }

    private fun getTClass(): Class<VM> {
        return (javaClass.genericSuperclass as ParameterizedType).actualTypeArguments[1] as Class<VM>
    }

    override fun pageLogical() {
        contentViewBinding.lifecycleOwner = this
    }

}